#!/usr/bin/env bash
VERSION=$1
DEB_VERSION=$2
RPM_VERSION=$3
[ -z "$VERSION" -o -z "$DEB_VERSION" -o -z "$RPM_VERSION" ] && exit 1

DIST_HOST="$(id -u -n)@$(hostname -f 2>/dev/null || hostname 2>/dev/null || echo localhost)"

sed -r "s/Version: (.*)/Version: $RPM_VERSION/" -i pdns.spec
sed -r "s/AC_INIT\(\[pdns\],(.*)/AC_INIT([pdns], [$VERSION])/" -i configure.ac
sed -r "s/^(.*)AC_SUBST\(\[DIST_HOST\],(.*)/AC_SUBST([DIST_HOST], [$DIST_HOST])/" -i configure.ac
sed -r "1 s/^pdns \\(([^)]*)-([0-9.])\\)/pdns \\($DEB_VERSION-\\2\\)/" -i debian/changelog

sed -r "s/#VERSION#/$VERSION/" -i build-scripts/redhat/pdns-server-test.spec
